package com.baosight.xdata.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * tss message
 */
@Data
public class TssEventMessageRecord implements Serializable {

    /**
     * topology instance id of the current finished process instance
     */
    private Integer topologyInstanceId;

    /**
     * process definition id
     */
    private Integer processDefinitionId;

    /**
     * the current finished process instance
     */
    private Integer processInstanceId;

    /**
     * process state
     */
    private Integer state;

    /**
     * partition by memory message producer shuffle
     */
    private Integer partition;

    /**
     * master workflow execute thread generate event time
     */
    private Date eventTime;

    /**
     *  event consumer processes event memory message time
     */
    private Date processTime;

    /**
     * event message processed master node
     */
    private String host;

    /**
     * topology instance triggered timestamp
     */
    private Long topologyTriggeredTimestamp;

    /**
     * pool id
     */
    private Integer poolId;

    /**
     * current event message whether or not belongs to topology recovery situation
     */
    private boolean enableRecovery = false;

    private boolean enableFirstNode = false;

    public boolean getEnableFirstNode() {
        return enableFirstNode;
    }

    public void setEnableFirstNode(boolean enableFirstNode) {
        this.enableFirstNode = enableFirstNode;
    }

    public boolean getEnableRecovery() {
        return enableRecovery;
    }

    public void setEnableRecovery(boolean enableRecovery) {
        this.enableRecovery = enableRecovery;
    }

    @Override
    public String toString() {
        return "TssEventMessageRecord{" +
                "topologyInstanceId=" + topologyInstanceId +
                ", processDefinitionId=" + processDefinitionId +
                ", processInstanceId=" + processInstanceId +
                ", state=" + state +
                ", partition=" + partition +
                ", eventTime=" + eventTime +
                ", processTime=" + processTime +
                ", host='" + host + '\'' +
                ", topologyTriggeredTimestamp=" + topologyTriggeredTimestamp +
                ", poolId=" + poolId +
                ", enableRecovery=" + enableRecovery +
                ", enableFirstNode=" + enableFirstNode +
                '}';
    }

    public Map<String, String> convert2Map(){
        Map<String, String> body =  new HashMap();
        body.put("topologyInstanceId", getTopologyInstanceId().toString());
        body.put("processDefinitionId", getProcessDefinitionId().toString());
        body.put("processInstanceId", getProcessInstanceId().toString());
        body.put("state", getState().toString());
        body.put("partition", getPartition().toString());
        return body;
    }
}
